﻿package mortal.game.view.wizard.newPanel
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.cache.packCache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.mount.panel.*;
    import mortal.game.view.wizard.data.*;
    import mortal.game.view.wizard.panel.*;
    import mortal.mvc.core.*;

    public class WizardEquipPart extends GSprite
    {
        private var _spEquipMentList:Vector.<OtherEquipItem>;
        private var _currentWizardData:WizardData;

        public function WizardEquipPart()
        {
            this._spEquipMentList = new Vector.<OtherEquipItem>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.createEquipList();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._currentWizardData = null;
            this._spEquipMentList.length = 0;
            super.disposeImpl(param1);
            return;
        }// end function

        private function createEquipList() : void
        {
            var _loc_1:OtherEquipItem = null;
            var _loc_2:int = 0;
            while (_loc_2 < 4)
            {
                
                _loc_1 = UICompomentPool.getUICompoment(OtherEquipItem);
                _loc_1.setItemStyle(ItemStyleConst.Small, ImagesConst.EquipItemBg, 7, 7);
                _loc_1.x = 508 * int(_loc_2 / 2);
                _loc_1.y = int(_loc_2 % 2) * 52;
                _loc_1.isShowLock = true;
                _loc_1.buttonMode = true;
                _loc_1.doubleClickEnabled = true;
                _loc_1.configEventListener(MouseEvent.CLICK, this.openSmallWin);
                _loc_1.configEventListener(MouseEvent.DOUBLE_CLICK, this.putOffEquip);
                this.pushUIToDisposeVec(_loc_1);
                this._spEquipMentList.push(_loc_1);
                this.addChild(_loc_1);
                _loc_2++;
            }
            return;
        }// end function

        private function resetAutoUpdateEquipItem() : void
        {
            var _loc_1:OtherEquipItem = null;
            var _loc_2:int = 0;
            while (_loc_2 < this._spEquipMentList.length)
            {
                
                _loc_1 = this._spEquipMentList[_loc_2];
                _loc_1.isAutoUpdateEquip(true, EGroup._EGroupProp, EProp._EPropSpriteEquip, _loc_2, EPlayerItemPosType._EPlayerItemPosTypeSprite + this._currentWizardData.code, -1, this._currentWizardData.code);
                _loc_2++;
            }
            return;
        }// end function

        private function getSmallWinTitleData() : Dictionary
        {
            var _loc_1:* = new Dictionary();
            _loc_1[0] = [{name:"equip", label:Language.getString(35608)}];
            _loc_1[1] = [{name:"equip", label:Language.getString(35609)}];
            _loc_1[2] = [{name:"equip", label:Language.getString(35610)}];
            _loc_1[3] = [{name:"equip", label:Language.getString(35611)}];
            _loc_1[99] = [{name:"equip", label:Language.getString(35612)}];
            return _loc_1;
        }// end function

        private function openSmallWin(event:MouseEvent) : void
        {
            if (!this._currentWizardData.isHasWizard)
            {
                return MsgManager.showRollTipsMsg(Language.getString(35613));
            }
            var _loc_2:* = event.currentTarget as OtherEquipItem;
            var _loc_3:* = this.getSmallWinTitleData();
            EquipBaseWin.instance.setWinData(_loc_3, EPlayerItemPosType._EPlayerItemPosTypeSprite + this._currentWizardData.code, EGroup._EGroupProp, EProp._EPropSpriteEquip, _loc_2.itemData.itemInfo.type, -1, this._currentWizardData.code);
            var _loc_4:* = this.localToGlobal(new Point(0, 0));
            EquipBaseWin.instance.show(_loc_4.x + 130, _loc_4.y - 20);
            return;
        }// end function

        private function putOffEquip(event:MouseEvent) : void
        {
            var _loc_3:OtherEquipItem = null;
            var _loc_4:ItemData = null;
            var _loc_5:Object = null;
            var _loc_2:* = Cache.instance.pack.getWizardPackCacheByCode(this._currentWizardData.tSprite.code);
            if (_loc_2)
            {
                _loc_3 = event.currentTarget as OtherEquipItem;
                _loc_4 = _loc_2.getItemDataByType(_loc_3.itemData.itemInfo.type);
                if (_loc_4)
                {
                    _loc_5 = new Object();
                    _loc_5.putonitemData = "";
                    _loc_5.getoffItemData = _loc_4;
                    _loc_5.code = this._currentWizardData.tSprite.code;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.WizardEquip, _loc_5));
                }
            }
            return;
        }// end function

        public function set data(param1:WizardData) : void
        {
            this._currentWizardData = param1;
            this.resetAutoUpdateEquipItem();
            return;
        }// end function

        public function updateEquipList() : void
        {
            var _loc_3:ItemData = null;
            var _loc_4:OtherEquipItem = null;
            var _loc_5:WizardPackCache = null;
            var _loc_1:* = WizardConfig.instance.getSpriteByCodeAndLevel(this._currentWizardData.code, 1);
            var _loc_2:* = _loc_1.equipId.split("#");
            if (this._currentWizardData.isHasWizard)
            {
                _loc_5 = Cache.instance.pack.getWizardPackCacheByCode(this._currentWizardData.tSprite.code);
            }
            var _loc_6:int = 0;
            while (_loc_6 < _loc_2.length)
            {
                
                _loc_4 = this._spEquipMentList[_loc_6];
                if (_loc_5)
                {
                    _loc_3 = _loc_5.getEquipByType(_loc_6);
                }
                else
                {
                    _loc_3 = null;
                }
                if (_loc_3)
                {
                    _loc_4.itemData = _loc_3;
                    _loc_4.midLabel = "";
                    _loc_4.bitmapEnable = true;
                    _loc_4.updateStrengLevel(_loc_3.itemInfo.itemLevel);
                }
                else
                {
                    _loc_3 = new ItemData(int(_loc_2[_loc_6]));
                    _loc_4.itemData = _loc_3;
                    _loc_4.midLabel = _loc_3.name;
                    _loc_4.bitmapEnable = false;
                    _loc_4.setColorBg(0);
                    _loc_4.clearStrengInfo();
                }
                _loc_6++;
            }
            return;
        }// end function

    }
}
